Page({
    data: {
      address: {}
    },
  
    onLoad(options) {
      const address = JSON.parse(options.address); // 获取传递的地址信息
      this.setData({
        address: address
      });
    },
  
    inputReceiver(event) {
      this.setData({
        'address.receiver': event.detail.value
      });
    },
  
    inputPhone(event) {
      this.setData({
        'address.phone': event.detail.value
      });
    },
  
    inputDetails(event) {
      this.setData({
        'address.details': event.detail.value
      });
    },
  
    toggleDefault(event) {
      this.setData({
        'address.isdefault': event.detail.value ? '是' : '否'
      });
    },
  
    submitForm() {
      const { address } = this.data;
  
      // 调用后端接口更新地址信息
      wx.request({
        url: `http://localhost:3000/updateAddress`,
        method: 'POST',
        data: address,
        success: (res) => {
          if (res.data.success) {
            wx.showToast({
              title: '修改成功',
              icon: 'success'
            });
            wx.navigateBack(); // 返回上一页面
          } else {
            wx.showToast({
              title: res.data.error,
              icon: 'none'
            });
          }
        },
        fail: () => {
          wx.showToast({
            title: '请求失败，请检查网络',
            icon: 'none'
          });
        }
      });
    }
  });
  